<?php
$num_to_guess = 42;
$num_tries = (isset($_POST["num_tries"])) ? $_POST["num_tries"]+1 : 1;
if (!isset($_POST["guess"])){
	$message = "Welcome to the guessing machine!";
} else if ($_POST["guess"] > $num_to_guess){
	$message = $_POST["guess"]." is too big! Try a smaller number.";
} else if ($_POST["guess"] < $num_to_guess){
	$message = $_POST["guess"]." is too small! Try a larger number.";
} else {
	//$message = "well done!";
	header("Location: congrats.html");
	exit;
}
//$guess = $_POST["guess"];
?>

<html>
<head>
<title> Using header() to Redirect User</title>
</head>
<body>
<h1><?php echo $message; ?></h1>
<p><strong>Guess number:</strong><?php echo $num_tries; ?></p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<p><strong>Type your guess here:</strong>
<input type="text" name="guess" /></p>
<input type="hidden" name="num_tries" value="<?php echo $num_tries; ?>"/>
<p><input type = "submit" value = "submit your guess" /></p>
</form>
</body>
</html>

